﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:agf="clr-namespace:AgFractal"
    xmlns:ge="clr-namespace:AgFractal.Controls.GradientEditor"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    x:Class="AgFractal.MainPage"
    xmlns:agc="clr-namespace:AgFractal.Controls"
    SizeChanged="UserControl_SizeChanged" mc:Ignorable="d" >
    <UserControl.Resources>
        <Storyboard x:Name="closea" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="fractalPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="-134"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="fractalPanel" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0.5"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="opena">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="fractalPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="fractalPanel" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="closemenu">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="menuPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="-104"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="menuPanel" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0.5"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="openmenu">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="menuPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="menuPanel" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        
        <Storyboard x:Name="showDrag">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="drag" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="hideDrag">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="drag" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0.5"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Name="showZoom">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                Storyboard.TargetName="zoom" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="hideZoom">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                Storyboard.TargetName="zoom" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0.25"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Name="showTime" >
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                Storyboard.TargetName="timeBorder" Storyboard.TargetProperty="Opacity">
                <SplineDoubleKeyFrame KeyTime="00:00:00.1" Value="0.2"/>
                <SplineDoubleKeyFrame KeyTime="00:00:02" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:03.5" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:05" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <Canvas Background="#FF111111">
        <Grid x:Name="LayoutRoot">
            <Canvas x:Name="imageCanvas" Grid.Column="1" VerticalAlignment="Center"                 
                HorizontalAlignment="Center" 
                MouseEnter="imageCanvas_MouseEnter" 
                MouseLeave="imageCanvas_MouseLeave" 
                MouseMove="imageCanvas_MouseMove"
                MouseLeftButtonDown="imageCanvas_MouseLeftButtonDown" 
                MouseLeftButtonUp="imageCanvas_MouseLeftButtonUp">
                <Rectangle x:Name="zoomRect" Visibility="Collapsed" Width="0" 
                       Canvas.ZIndex="1"
                       Height="0" Stroke="White" StrokeThickness="1"/>
                <agc:ImagePresenter x:Name="fractalPresenter" IsDraggable="False" Dragged="fractalPresenter_Dragged" HorizontalAlignment="Right" />
            </Canvas> 
            <Border HorizontalAlignment="Center" x:Name="timeBorder" Opacity="0" IsHitTestVisible="False"
                    BorderBrush="Black" BorderThickness="1" VerticalAlignment="Center"
                    Background="WhiteSmoke" Padding="5" CornerRadius="7" Width="100">
                <TextBlock Text="0:10.25" HorizontalAlignment="Center" x:Name="timeTextBlock"/>
            </Border>
            <StackPanel x:Name="tools" HorizontalAlignment="Right"  
                        Orientation="Horizontal" VerticalAlignment="Top" >
                <Border Background="White" CornerRadius="7" Width="30" Height="30" 
                        MouseLeftButtonUp="drag_Click" x:Name="drag" MouseEnter="drag_MouseEnter" 
                        MouseLeave="drag_MouseLeave" Opacity="0.5">
                    <Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Padding="2" Margin="2" >
                        <Image Source="Icons/hand.png" MouseLeftButtonUp="drag_Click"/>
                    </Border>
                </Border>
                <Border Background="White"  CornerRadius="7" Width="30" Height="30" Margin="2,0,0,0" Canvas.ZIndex="2"
                        MouseLeftButtonUp="zooming_Click" x:Name="zoom" Opacity="0.5">
                    <Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Padding="2" Margin="2">
                        <Image Source="Icons/zoom.png" MouseLeftButtonUp="zooming_Click" 
                        MouseEnter="zoom_MouseEnter" MouseLeave="zoom_MouseLeave"/>
                    </Border>
                </Border>
                <Border Background="White"  CornerRadius="7" Width="30" Height="30" Margin="2,0,0,0" Canvas.ZIndex="2"
                        MouseLeftButtonUp="gradientMouseUp" >
                    <Border BorderBrush="Black" BorderThickness="1" CornerRadius="5" Padding="2" Margin="2">
                    	<Rectangle Stroke="Black" Margin="2,3,2,2">
                    		<Rectangle.Fill>
                    			<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    				<GradientStop Color="Black" Offset="1"/>
                    				<GradientStop Color="White"/>
                    			</LinearGradientBrush>
                    		</Rectangle.Fill>
                    	</Rectangle>
                    </Border>
                </Border>
            </StackPanel>
            <Popup x:Name="parameterPopup" Width="185" Height="135">
                <agc:ParameterUC x:Name="parameterUC" />
            </Popup>
            <Popup x:Name="newFractalPopup" Width="730" Height="550">
                <agc:NewFractalUserControl x:Name="newFractalUC" Width="730" Height="450"/>
            </Popup>
            <Popup x:Name="gradientEditorPopup" Width="645" Height="258">
                <ge:GradientEditor x:Name="gradientEditor"/>
            </Popup>
        </Grid>
        <Border Canvas.Left="200" x:Name="zoomPanel"
                BorderThickness="2"
                Background="#FF111111"
                Margin="0" BorderBrush="WhiteSmoke" 
                CornerRadius="0,0,10,10" Canvas.ZIndex="1" >
            <StackPanel Margin="4,2,4,4">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="(R1,I1):" Foreground="#FFAAAAAA" VerticalAlignment="Center"/>
                    <TextBox IsReadOnly="True" Text="{Binding ZoomR1, Mode=TwoWay}" Width="128" Style="{StaticResource GlossyBlackTextBox}"/>
                    <TextBlock Text="," Foreground="#FFAAAAAA" VerticalAlignment="Center"/>
                    <TextBox IsReadOnly="True" Text="{Binding ZoomI1, Mode=TwoWay}" Width="128" Style="{StaticResource GlossyBlackTextBox}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,2,0,0">
                    <TextBlock Text="(R2,I2):" Foreground="#FFAAAAAA" VerticalAlignment="Center"/>
                    <TextBox IsReadOnly="True" Text="{Binding ZoomR2, Mode=TwoWay}" Width="128" Style="{StaticResource GlossyBlackTextBox}"/>
                    <TextBlock Text="," Foreground="#FFAAAAAA" VerticalAlignment="Center"/>
                    <TextBox IsReadOnly="True" Text="{Binding ZoomI2, Mode=TwoWay}" Width="128" Style="{StaticResource GlossyBlackTextBox}"/>
                </StackPanel>
                <TextBlock Text="Zoom" HorizontalAlignment="Center" Margin="0,0,0,-3" Foreground="White" FontWeight="Bold"/>
            </StackPanel>
        </Border>
        <Border Width="154" x:Name="fractalPanel" BorderThickness="2" Opacity="0.5"
                Background="#FF111111" BorderBrush="WhiteSmoke" 
                CornerRadius="0,10,10,0" Canvas.ZIndex="1" MouseEnter="panel_MouseEnter" MouseLeave="panel_MouseLeave"
                >
            <Border.RenderTransform>
                <TranslateTransform X="-134"/>
            </Border.RenderTransform>
            <StackPanel Margin="2,4,4,4" Orientation="Horizontal" >
                <StackPanel x:Name="inputPanel" >
                    <StackPanel Orientation="Horizontal" Margin="0,0,-5,0"
                        HorizontalAlignment="Right" />
                    <TextBlock Text="Fractal:" Foreground="#FFAAAAAA"/>
                    <TextBox Text="{Binding Fractal.Name, Mode=TwoWay}" Style="{StaticResource GlossyBlackTextBox}" Width="128" IsReadOnly="True"/>
						
                    <TextBlock Text="R1:" Foreground="#FFAAAAAA"/>
                    <TextBox Text="{Binding R1, Mode=TwoWay}" Style="{StaticResource GlossyBlackTextBox}" Width="128"/>

                    <TextBlock Text="I1:" Foreground="#FFAAAAAA"/>
                    <TextBox Text="{Binding I1, Mode=TwoWay}" Style="{StaticResource GlossyBlackTextBox}" Width="128"/>

                    <TextBlock Text="R2:" Foreground="#FFAAAAAA"/>
                    <TextBox Text="{Binding R2, Mode=TwoWay}" Style="{StaticResource GlossyBlackTextBox}" Width="128"/>

                    <TextBlock Text="I2:" Foreground="#FFAAAAAA"/>
                    <TextBox Text="{Binding I2, Mode=TwoWay}" Style="{StaticResource GlossyBlackTextBox}" Width="128"/>

                    <TextBlock Text="Iteration:"  Foreground="#FFAAAAAA"/>
                    <TextBox x:Name="iter" Text="{Binding Iteration, Mode=TwoWay}" LostFocus="iter_LostFocus" Style="{StaticResource GlossyBlackTextBox}" Width="128"/>

                    <Button Content="Calculate" Style="{StaticResource BlackGlossyButton}" Click="Calculate_click" Margin="0,4"/>
                    <Button Content="Parameter..." Style="{StaticResource BlackGlossyButton}" IsEnabled="{Binding HasParameter}" Margin="0,4,0,4" Click="Parameter_Click" />
                </StackPanel>
                <TextBlock Text="Fractal" HorizontalAlignment="Center" 
					Foreground="White"
					VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" FontWeight="Bold" >
					<TextBlock.RenderTransform>
						<TransformGroup>
							<ScaleTransform/>
							<SkewTransform/>
							<RotateTransform Angle="-90"/>
							<TranslateTransform X="-11"/>
						</TransformGroup>
					</TextBlock.RenderTransform>
                </TextBlock>
            </StackPanel>
        </Border>
        <Border Width="124" x:Name="menuPanel" BorderThickness="2"
                Background="#FF111111" BorderBrush="WhiteSmoke" 
                CornerRadius="0,10,10,0" Canvas.ZIndex="1" Opacity="0.5"
                Canvas.Top="336" MouseEnter="menuPanel_MouseEnter" MouseLeave="menuPanel_MouseLeave" 
                >
            <Border.RenderTransform>
                <TranslateTransform X="-104"/>
            </Border.RenderTransform>
            <StackPanel Margin="2,4,4,4" Orientation="Horizontal" >
            	<StackPanel>
            		<Button Content="Back" Style="{StaticResource BlackGlossyButton}" Click="Back_Click"/>
            		<Button Content="Full screen" x:Name="fullScreen" Style="{StaticResource BlackGlossyButton}" Click="fullScreen_Click" Margin="0,4"/>
            		<Button Content="New fractal" Click="New_click"  x:Name="newButton" Style="{StaticResource BlackGlossyButton}" IsEnabled="False" />
                    <Button Content="Save" Click="saveButton_Click"  x:Name="saveButton" Style="{StaticResource BlackGlossyButton}" Margin="0,4"/>
                    <Button Content="Load" Click="loadButton_Click" x:Name="loadButton" Style="{StaticResource BlackGlossyButton}"/>
                    <Button Content="Export" Click="exportButton_Click"  x:Name="exportButton" Style="{StaticResource BlackGlossyButton}" Margin="0,4,0,0"/>
            	</StackPanel>
				<TextBlock Text="Menu" HorizontalAlignment="Center" 
					Foreground="White"
					VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" FontWeight="Bold" Margin="2,0,0,0" >
					<TextBlock.RenderTransform>
						<TransformGroup>
							<ScaleTransform/>
							<SkewTransform/>
							<RotateTransform Angle="-90"/>
							<TranslateTransform X="-11"/>
						</TransformGroup>
					</TextBlock.RenderTransform>
				</TextBlock>
            </StackPanel>
        </Border>
    </Canvas>
</UserControl>